package com.imonsoft.sqm.dao.sys;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import com.imonsoft.common.httpModel.DataGrid;
import com.imonsoft.common.httpModel.Pager;
import com.imonsoft.sqm.pojo.sys.Role;
import com.imonsoft.sqm.pojo.sys.RoleExample;

@SuppressWarnings("deprecation")
@Repository("roleDAO")
public class RoleDAOImpl extends SqlMapClientDaoSupport implements RoleDAO {

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_role
	 * @ibatorgenerated  Sat Jun 01 11:24:59 CST 2013
	 */
	public RoleDAOImpl() {
		super();
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_role
	 * @ibatorgenerated  Sat Jun 01 11:24:59 CST 2013
	 */
	public int countRoleByExample(RoleExample example) {
		Integer count = (Integer) getSqlMapClientTemplate().queryForObject(
				"ts_role.ibatorgenerated_countByExample", example);
		return count;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_role
	 * @ibatorgenerated  Sat Jun 01 11:24:59 CST 2013
	 */
	public int deleteRoleByExample(RoleExample example) {
		int rows = getSqlMapClientTemplate().delete(
				"ts_role.ibatorgenerated_deleteByExample", example);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_role
	 * @ibatorgenerated  Sat Jun 01 11:24:59 CST 2013
	 */
	public int deleteRoleByPrimaryKey(Long id) {
		Role key = new Role();
		key.setId(id);
		int rows = getSqlMapClientTemplate().delete(
				"ts_role.ibatorgenerated_deleteByPrimaryKey", key);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_role
	 * @ibatorgenerated  Sat Jun 01 11:24:59 CST 2013
	 */
	public Long insertRole(Role record) {
		Object newKey = getSqlMapClientTemplate().insert(
				"ts_role.ibatorgenerated_insert", record);
		return (Long) newKey;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_role
	 * @ibatorgenerated  Sat Jun 01 11:24:59 CST 2013
	 */
	public Long insertRoleSelective(Role record) {
		Object newKey = getSqlMapClientTemplate().insert(
				"ts_role.ibatorgenerated_insertSelective", record);
		return (Long) newKey;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_role
	 * @ibatorgenerated  Sat Jun 01 11:24:59 CST 2013
	 */
	@SuppressWarnings("unchecked")
	public List<Role> selectRoleByExample(RoleExample example) {
		List<Role> list = getSqlMapClientTemplate().queryForList(
				"ts_role.ibatorgenerated_selectByExample", example);
		return list;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_role
	 * @ibatorgenerated  Sat Jun 01 11:24:59 CST 2013
	 */
	public Role selectRoleByPrimaryKey(Long id) {
		Role key = new Role();
		key.setId(id);
		Role record = (Role) getSqlMapClientTemplate().queryForObject(
				"ts_role.ibatorgenerated_selectByPrimaryKey", key);
		return record;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_role
	 * @ibatorgenerated  Sat Jun 01 11:24:59 CST 2013
	 */
	public int updateRoleByExampleSelective(Role record, RoleExample example) {
		UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
		int rows = getSqlMapClientTemplate().update(
				"ts_role.ibatorgenerated_updateByExampleSelective", parms);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_role
	 * @ibatorgenerated  Sat Jun 01 11:24:59 CST 2013
	 */
	public int updateRoleByExample(Role record, RoleExample example) {
		UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
		int rows = getSqlMapClientTemplate().update(
				"ts_role.ibatorgenerated_updateByExample", parms);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_role
	 * @ibatorgenerated  Sat Jun 01 11:24:59 CST 2013
	 */
	public int updateRoleByPrimaryKeySelective(Role record) {
		int rows = getSqlMapClientTemplate().update(
				"ts_role.ibatorgenerated_updateByPrimaryKeySelective", record);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table ts_role
	 * @ibatorgenerated  Sat Jun 01 11:24:59 CST 2013
	 */
	public int updateRoleByPrimaryKey(Role record) {
		int rows = getSqlMapClientTemplate().update(
				"ts_role.ibatorgenerated_updateByPrimaryKey", record);
		return rows;
	}

	/**
	 * This class was generated by Apache iBATIS ibator. This class corresponds to the database table ts_role
	 * @ibatorgenerated  Sat Jun 01 11:24:59 CST 2013
	 */
	private static class UpdateByExampleParms extends RoleExample {
		private Object record;

		public UpdateByExampleParms(Object record, RoleExample example) {
			super(example);
			this.record = record;
		}

		@SuppressWarnings("unused")
		public Object getRecord() {
			return record;
		}
	}

    @SuppressWarnings("unchecked")
    @Override
    public DataGrid<Role> getDataGrid(RoleExample example, Pager pager) {
        if (example == null) {
            example = new RoleExample();
        }
        int total = countRoleByExample(example);
        List<Role> rows = getSqlMapClientTemplate().queryForList("ts_role.ibatorgenerated_selectByExample", example, pager.getSkipResults(), pager.getRows());
        DataGrid<Role> dataGrid = new DataGrid<Role>(total, rows);
        return dataGrid;
    }
 
    @SuppressWarnings("unchecked")
	@Override
	public List<Role> getRoleListByUserId(Long userId) {
		return getSqlMapClientTemplate().queryForList("ts_role.getRoleListByUserId",userId);
	}
}